<template>
  <div>
    <avue-crud
      :data="dataList"
      :option="option"
      :page="page"
      @refresh-change="getDataList"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @on-load="getDataList"
    >
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          size="small"
          icon="el-icon-s-operation"
          @click="openTbRecordsDialog(scope.row)"
          >投标记录
        </el-button>
      </template>
    </avue-crud>
    <el-dialog
      title="投标记录"
      :visible.sync="tbRecodesDialogVisible"
      fullscreen
    >
      <span>
        <avue-crud
          :data="tbRecodes"
          :option="tbRecordsOption"
          :page="tbRecodesPage"
          @refresh-change="getTbRecodes"
          @search-change="tbRecodesSearchChange"
          @search-reset="tbRecodesSearchReset"
          @selection-change="selectionChange"
          @current-change="tbRecodesCurrentChange"
          @size-change="tbRecodesSizeChange"
        >
          <template slot-scope="scope" slot="menuLeft">
            <el-button
              type="primary"
              size="small"
              icon="el-icon-sort"
              @click="setOrderNum()"
              >抽签排序
            </el-button>
          </template>

          <template slot-scope="scope" slot="menu">
            <el-button
              v-if="scope.row.status == 0"
              type="text"
              size="small"
              icon="el-icon-bell"
              @click="openSecondaryQuotation(scope.row)"
              >开启二次报价
            </el-button>
            <el-button
              v-if="scope.row.status == 2"
              type="text"
              size="small"
              icon="el-icon-view"
              @click="viewSecondaryQuotation(scope.row)"
              >查看二次报价
            </el-button>
          </template>
          <template slot-scope="scope" slot="decryptFileUrl">
            <el-tag
              v-if="
                scope.row.decryptFileUrl == null ||
                scope.row.decryptFileUrl == ''
              "
              type="danger"
              size="small"
              >已加密</el-tag
            >
            <el-tooltip v-else content="点击查看" placement="top" effect="dark">
              <el-tag
                type="success"
                size="small"
                @click="view(scope.row.decryptFileUrl)"
                >查看</el-tag
              >
            </el-tooltip>
          </template>
        </avue-crud>
      </span>
      <span slot="footer">
        <el-button @click="tbRecodesDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="save">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { baseUrl } from "@/config/env";
import request from "@/router/axios";
import { getStore } from "@/util/store";

export default {
  name: "errLogs",
  data() {
    return {
      queryForm: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      dataList: [],

      option: {
        menu: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        page: true,
        border: true,
        expand: false,
        refreshBtn: true,
        headerAlign: "center",
        searchShow: true,
        searchMenuSpan: 6,
        column: [
          {
            label: "招标单号",
            prop: "spNo",
            width: 180,
            align: "center",
            solt: false,
            search: true,
          },
          {
            label: "备案编号",
            width: 200,
            prop: "beianNo",
            overHidden: true,
          },
          {
            label: "关联申请内容",
            prop: "glSpName",
            overHidden: true,
            align: "center",
            width: 300,
            solt: false,
            search: true,
          },
          {
            label: "招标方式",
            prop: "zbfs",
            hide: true,
          },
          {
            label: "挂网时间",
            align: "center",
            prop: "gwsj",
            width: 200,
          },
          {
            label: "报名开始时间",
            align: "center",
            prop: "signStartTime",
            width: 200,
          },
          {
            label: "报名结束时间",
            align: "center",
            prop: "signEndTime",
            width: 200,
          },
        ],
      },
      tbRecodesDialogVisible: false,
      tbRecodesQueryForm: {
        zczxId: "",
      },
      tbRecodesPage: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      tbRecodes: [],
      tbRecordsOption: {
        menu: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        page: true,
        border: true,
        expand: false,
        refreshBtn: true,
        headerAlign: "center",
        searchShow: true,
        searchMenuSpan: 6,
        column: [
           {
            label: "招标单号",
            prop: "id",
            width: 180,
            align: "center",
            solt: false,
            search: true,
          },
          {
            label: "招标单号",
            prop: "glSpNo",
            width: 180,
            align: "center",
            solt: false,
            search: true,
          },
          {
            label: "项目名称",
            width: 200,
            align: "center",
            prop: "zczxName",
            overHidden: true,
          },
          {
            label: "投标人",
            prop: "name",
            overHidden: true,
            align: "center",
            solt: false,
            search: true,
          },
          {
            label: "投标人手机",
            prop: "phone",
            align: "center",
            width: 120,
          },

          {
            label: "投标人身份证",
            align: "center",
            prop: "idCard",
            width: 250,
          },
          {
            label: "抽签顺序",
            prop: "orderNum",
            align: "center",
            width: 80,
          },
          {
            label: "投标文件",
            align: "center",
            prop: "decryptFileUrl",
            slot: true,
          },
          {
            label: "状态",
            align: "center",
            prop: `status`,
            width: 150,
            dicData: [
              {
                label: "默认状态",
                value: 0,
              },
              {
                label: "等待二次报价",
                value: 1,
              },
              {
                label: "二次报价完成",
                value: 2,
              },
            ],
          },
          {
            label: "投标人所在公司",
            align: "center",
            prop: "company",
            width: 200,
          },
          {
            label: "投标时间",
            align: "center",
            prop: "createTime",
            width: 200,
          },
        ],
      },
    };
  },
  created() {
    this.getDataList();
  },
  mounted() {},
  computed: {},
  props: [],
  methods: {
    getDataList() {
      let requestUrl =
        baseUrl +
        "/api/blade-ztb/tendermzczx/page?current=" +
        this.page.currentPage +
        "&pageSize=" +
        this.page.pageSize;
      request({
        url: requestUrl,

        method: "get",
        params: this.queryForm,
      })
        .then((res) => {
          console.log("=res=", res);
          if (res.data.code == 200) {
            this.dataList = res.data.data.records;
            this, (this.page.total = res.data.data.total);
            console.log("=dataList =", this.dataList);
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },

    searchReset() {
      this.queryForm = {};
      this.getDataList();
    },
    searchChange(params) {
      this.queryForm = Object.assign(params, this.queryForm);
      this.getDataList();
    },

    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.getDataList();
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getDataList();
    },
    // 投标记录start
    openTbRecordsDialog(row) {
      console.log("=openTbRecordsDialog==", row);
      this.tbRecodesQueryForm.zczxId = row.id;
      this.getTbRecodes();
      this.tbRecodesDialogVisible = true;
    },

    getTbRecodes() {
      let requestUrl =
        baseUrl +
        "/api/blade-ztb/tbrecords/pageByZczxId/" +
        this.tbRecodesQueryForm.zczxId +
        "?current=" +
        this.tbRecodesPage.currentPage +
        "&pageSize=" +
        this.tbRecodesPage.pageSize;
      request({
        url: requestUrl,
        method: "get",
        params: this.queryForm,
      })
        .then((res) => {
          if (res.data.code == 200) {
            this.tbRecodes = res.data.data.records;
            this.tbRecodesPage.total = res.data.data.total;
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },

    tbRecodesSearchReset() {
      this.tbRecodesQueryForm = {};
      this.getTbRecodes();
    },
    tbRecodesSearchChange(params) {
      this.tbRecodesQueryForm = Object.assign(params, this.tbRecodesQueryForm);
      this.getTbRecodes();
    },

    tbRecodesCurrentChange(currentPage) {
      this.tbRecodesPage.currentPage = currentPage;
      this.getTbRecodes();
    },
    tbRecodesSizeChange(pageSize) {
      this.tbRecodesPage.pageSize = pageSize;
      this.getTbRecodes();
    },
    // end

    // // 解压
    // unrar(){
    //   this.$prompt('请输入密码', '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       inputType:"password"
    //     }).then(({ value }) => {
    //       const requestUrl = baseUrl + "/api/blade-ztb/tbrecords/unrar"
    //       request({
    //         url: requestUrl,

    //     });
    //     console.log("准备解压:",value);
    //     }).catch(() => {
    //       console.info("取消输入");
    //     });
    // },

    view(url) {
      this.$confirm("确认查看?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          window.open(url, "_blank");
        })
        .catch(() => {
          console.info("已取消");
        });
    },

    openSecondaryQuotation(row) {
      let requestUrl =
        baseUrl + "/api/blade-ztb/tbrecords/changeStatus/" + row.id + "/" + 1;
      request({
        url: requestUrl,
        method: "get",
      })
        .then((res) => {
          console.log("==res==", res);
          if (res.data.code == 200) {
            this.$message.success("开启二次报价成功");
          } else {
            this.$message.warning("开启二次报价失败");
          }
        })
        .catch((e) => {
          console.error(e);
        });
    },

    viewSecondaryQuotation(row) {
      this.$confirm("确认查看?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$alert(row.secondaryQuotation, "二次报价结果", {
            confirmButtonText: "确定",
            callback: (action) => {},
          });
        })
        .catch(() => {
          console.info("已取消");
        });
    },

    setOrderNum() {
      this.$confirm("请先确认所有人都已投标?", "提示", {
        confirmButtonText: "我已确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const requestUrl =
            baseUrl + "/api/blade-ztb/tbrecords/setOrderNum/" +  this.tbRecodesQueryForm.zczxId;
          request({
            url: requestUrl,
            method: "get",
          })
            .then((res) => {
              if (res.status == 200) {
                this.$message.success("抽签排序成功");
                this.getTbRecodes();
              } else {
                this.$message.warning("抽签排序失败");
              }
            })
            .catch((e) => {});
        })
        .catch((e) => {
          console.info("已取消",e);
        });
    },

    reset(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.code {
  font-size: 12px;
  display: block;
  font-family: monospace;
  white-space: pre;
  margin: 1em 0px;
}
</style>
